        var bvStore = new Ext.data.JsonStore({
    		url: '/weihe/getItems_bvList',
			root: 'datas',
			fields : [{
			        	   name:'bvId',mapping:'id'
			          },{
			        	   name:'bvAmount',mapping:'amount' 
			          },{
        				   name:'bvPrice',mapping:'unitPrice'
        			  },{
        				   name:'bvUnit',mapping:'unit'
        			  },{
        				   name:'bvQty',mapping:'qty'
        			  },{
        				   name:'bvDog',mapping:'dog'
        			  }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_bvList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
        var bvListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_bvList',
			root: 'datas',
			fields : [{
			        	   name:'bvListId',mapping:'id'
			          },{
			        	   name:'bvCompany',mapping:'company' 
			          },{
        				   name:'bvAddress',mapping:'address'
        			  },{
        				   name:'bvDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'bvDestination',mapping:'destination'
        			  },{
        				   name:'bvFobChina',mapping:'fobChina'
        			  },{
        				   name:'bvInvoiceNum',mapping:'invoiceNum'
        			  },{
        				   name:'bvOceanFreight',mapping:'oceanFreight'
        			  },{
        				   name:'bvOrderNum',mapping:'orderNum'
        			  },{
        				   name:'bvSud',mapping:'sud'
        			  },{
        				   name:'bvTotal',mapping:'total'
        			  },{
        				   name:'bvState',mapping:'state'
        			  },{
        				   name:'bvNumber',mapping:'number'
        			  }],
        			  listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_bvList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
       
        
bvs = function(){
	
	var tmp='';

	
  return{
	  
	  
		listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height :250,
			                    items  : [bvs.listGrid(),bvs.listForm()] 
		                      });
	  
	  return listPanel;
},

listForm : function(){
	  
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					Ext.getCmp("bvsForm").buttons[0].enable();
					Ext.getCmp("bvsForm").buttons[1].enable();
					Ext.getCmp("bvsForm").buttons[2].enable();
					if (listForm.form.findField("bvListId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_bvList',
						     success : function(form, action) {
							      if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								        Ext.getCmp("bvListForm").form.findField('bvList.id').setValue(action.result.bvList_id);
									    Ext.getCmp("bvsForm").form.findField('bvList.id').setValue(action.result.bvList_id);
									    Ext.getCmp("bvListGrid").getStore().load({params : {start : action.result.total-1, limit : 5}});
									    listForm.buttons[0].setText('修改');
								        })
							       }
						     }
					      })
					}else {
							listForm.form.submit({
								url : '/weihe/update_bvList',
								success : function(form, action) {
									if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("bvListGrid").getStore().load({params : {start : 0, limit : 5}});
										})
									}
							   }
							})
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("bvsForm").form.reset();
			Ext.getCmp("bvsForm").buttons[0].disable();
		    Ext.getCmp("bvsForm").buttons[1].disable();
		    Ext.getCmp("bvsForm").buttons[2].disable();
		    Ext.getCmp("bvGrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('bvListId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_bvList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							  if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										listForm.form.reset();
										listForm.buttons[0].setText('添加');
							}else{
								Ext.Msg.alert('消息', json.msg, function() {
									Ext.getCmp("bvListGrid").getStore().load({params : {start : 0, limit : 5}});
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
								});
							  }
							}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'bvList.id' : listForm.form.findField('bvListId').getValue() }
				});
			}
		}
	});
	
	  
			var listForm = new Ext.form.FormPanel({
			id : 'bvListForm',
			region : 'east',
			title : 'bv信息',
			frame : true,
			width : 330,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{  // Ext.form.Hidden
				id: 'bvListId',
				xtype : 'hidden',  // 隐藏的表单
				name : 'bvList.id'
			},{
				id: 'bvCompany',
				fieldLabel: "Company",
				name: "bvList.company"
			},{
				id: 'bvAddress',
				fieldLabel: "Address",
				name: "bvList.address"
			},{
				id: 'bvInvoiceNum',
				fieldLabel: "InvoiceNO.",
          	    name: "bvList.invoiceNum"
			},{
				id: 'bvDate',
                xtype: 'datefield',
                fieldLabel: "DATE", //第三行，出生日期 
                format : 'Y-m-d',
    			allowBlank:false,
                name: "bvList.date"
			},{
				id: 'bvOrderNum',
				fieldLabel: "OrderNo.",
          	    name: "bvList.orderNum"
			},{
				id: 'bvDestination',
				 fieldLabel: "DESTINATION",
                 name: "bvList.destination"
			},{
				id: 'bvOceanFreight',
				 fieldLabel: "OceanFreight",
               name: "bvList.oceanFreight"
			},{
				id: 'bvSud',
				 fieldLabel: "SAYUSDOLLARS",
                name: "bvList.sud"
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : bvListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'bvListGrid',
		   title : 'bv信息表',
		   region : 'center',
		   minColumnWidth : 35,
		      tbar:[{
			  	text:"打印形式发票",
				handler:function(){
							if(tmp!=''){
			   				window.open('/weihe/printBV?bvList.id='+ tmp, '_blank');
			   				tmp = '';
							}else{
								Ext.Msg.alert('提示','请选择要打印的数据!');
							}
				}
						
		   		},"-",'查看方式:',new Ext.form.ComboBox({
											width: 60,
											triggerAction:'all',
											mode: 'local',
											displayField:'type',
											value:'全部',
											listeners:{
												'select':function(combo){
												   var type = combo.getValue();
												   if(type == '全部'){
													   listGrid.getStore().baseParams = {'type': "全部"};
													    listGrid.getStore().load({params : {start : 0, limit : 5}});
													   
												
													}else{
														 listGrid.getStore().baseParams = {'type': type}
														 listGrid.getStore().load({params : {start : 0, limit : 5,'type':combo.getValue()}});
													}
												}
											},
											store:new Ext.data.SimpleStore({
															data:['新建','返回','完结','全部'],
															expandData:true,
															fields:['type']
											})
										})
		   		,"-",{
		  			text:"设置完结",
					handler:function(){
		   			     if(tmp!=''){
		   						Ext.Ajax.request({
										url : '/weihe/finish_bvList',
										success : function(response) {
												var json = Ext.decode(response.responseText);
												if (json.success) {
														Ext.Msg.alert('消息', json.msg, function() {
																	 listGrid.getStore().reload();
														});
												}else{
														Ext.Msg.alert('消息', json.msg);
												}
										},
						  	   			failure : function() {
												Ext.Msg.alert('错误','删除错误!');
						   				},
										params : 'bvList.id=' + tmp
								});
		   							tmp='';
		   					}else{
		   							Ext.Msg.alert('提示','请在下方表中选择需要设置完结的形式发票！')
		   					}
					}
	   		},"-"],
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : bvListStore,
		   columns: [
		             {header : '状态', dataIndex : 'bvState'},
		             {header : '号码', dataIndex : 'bvNumber'},
		             {header : 'Company', dataIndex : 'bvCompany'},
		             {header : 'Address', dataIndex : 'bvAddress'},
		             {header : 'InvoiceNO.', dataIndex : 'bvInvoiceNum', menuDisabled : true},
		             {header : 'DATE', dataIndex : 'bvDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : 'OrderNo.', dataIndex : 'bvOrderNum', menuDisabled : true},
		             {header : 'DESTINATION', dataIndex : 'bvDestination', menuDisabled : true},
		             {header : 'OceanFreight', dataIndex : 'bvOceanFreight', menuDisabled : true},
		             {header : 'FOBCHINA', dataIndex : 'bvFobChina', menuDisabled : true},
		             {header : 'Total', dataIndex : 'bvTotal', menuDisabled : true},
		             {header : 'SAYUSDOLLARS', dataIndex : 'bvSud', menuDisabled : true}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		tmp = record.id;
			   		Ext.getCmp("bvListForm").form.loadRecord(record);
			   		Ext.getCmp("bvsForm").form.findField('bvList.id').setValue(record.id);
			   		Ext.getCmp("bvsForm").buttons[0].enable();
					Ext.getCmp("bvsForm").buttons[1].enable();
					Ext.getCmp("bvsForm").buttons[2].enable();
					Ext.getCmp("bvListForm").buttons[0].setText('修改');
					Ext.getCmp("bvGrid").getStore().baseParams = {'bvList.id': record.id};
					Ext.getCmp("bvGrid").getStore().load({params : {start : 0, limit : 5}});
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
  
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : bvStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'bvGrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : bvStore,
		   columns: [
		             {header : 'QTY', dataIndex : 'bvQty', menuDisabled : true},
		             {header : 'DESCRIPTION OF GOODS', dataIndex : 'bvDog'},
		             {header : 'UNIT PRICE（USD）', dataIndex : 'bvPrice', menuDisabled : true},
		             {header : 'AMOUNT（USD）', dataIndex : 'bvAmount', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("bvsForm").form.loadRecord(record);
			   Ext.getCmp("bvsForm").buttons[0].setText('修改');
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	bvsForm : function(){
		
		

		var button_add = new Ext.Button({
			text : '添加',
			disabled : true,
			handler : function() {

					progressConsole();
				if(bvsForm.form.isValid()){ 	
					if (bvsForm.form.findField("bvItem.id").getValue() == "") {
						bvsForm.form.submit({
						  url : '/weihe/addItem_bvList',
						   success : function(form, action) {
							 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									 var i = bvsForm.form.findField('bvList.id').getValue();
									   bvsForm.form.reset();
									   bvsForm.form.findField('bvList.id').setValue(i);
									   Ext.getCmp("bvGrid").getStore().baseParams = {'bvList.id': i};
									   Ext.getCmp("bvGrid").getStore().load({params : {start : 0, limit : 6}});
									   Ext.getCmp("bvListGrid").getStore().reload();
									
								})
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    })
					}else {
						bvsForm.form.submit({
							  url : '/weihe/updateItem_bvList',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = bvsForm.form.findField('bvList.id').getValue();
										bvsForm.form.reset();
										 bvsForm.form.findField('bvList.id').setValue(i);
										 Ext.getCmp("bvGrid").getStore().reload();
										 Ext.getCmp("bvListGrid").getStore().reload();
										 bvsForm.buttons[0].setText('添加');
										
									})
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = bvsForm.form.findField('bvList.id').getValue();
			bvsForm.form.reset();
			bvsForm.form.findField('bvList.id').setValue(i);
		    bvsForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = bvsForm.form.findField('bvItem.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteItem_bvList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
								  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									var i = bvsForm.form.findField('bvList.id').getValue();
										bvsForm.form.reset();
										bvsForm.form.findField('bvList.id').setValue(i);
										bvsForm.buttons[0].setText('添加');
								}else{
									Ext.Msg.alert('消息', json.msg, function() {
										Ext.getCmp("bvGrid").getStore().load({params : {start : 0, limit :6}});
										var i = bvsForm.form.findField('bvList.id').getValue();
										bvsForm.form.reset();
										bvsForm.form.findField('bvList.id').setValue(i);
										bvsForm.buttons[0].setText('添加');
										Ext.getCmp("bvGrid").getStore().reload();
										Ext.getCmp("bvListGrid").getStore().reload();
									});
								}
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'bvItem.id': id , 'bvList.id' : bvsForm.form.findField('bvList.id').getValue() }

				});
			}
		}
	});
	
		var bvsForm = new Ext.form.FormPanel({
			id : 'bvsForm',
			title : '货物信息',
			frame : true,
			width : 300,
			region : 'east',
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'bvId',
				xtype : 'hidden',
				name : 'bvItem.id'
			},{
				xtype : 'hidden',
				name : 'bvList.id'
			},{
				id:'bvDog',
				fieldLabel : '货物描述',
				allowBlank:false,
				name : 'bvItem.dog',
				blankText:'请输入货物描述'
			},{
				id:'bvQty',
				fieldLabel : '数量',
				name : 'bvItem.qty',
				allowBlank:false,
				blankText:'请输入数量'
			},{
				id:'bvUnit',
				fieldLabel : '单位',
				allowBlank:false,
				name : 'bvItem.unit',
				blankText:'请输入单位'
			},{
				id:'bvPrice',
				fieldLabel : '单价',
				allowBlank:false,
				name : 'bvItem.unitPrice',
				blankText:'请输入单价'
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return bvsForm;
	}
  }
}();








